/*
package org.itboys.weixin.web.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.itboys.admin.tools.AdminSessionHolder;
import org.itboys.admin.tools.LoginUser;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.io.FileUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mongodb.utils.query.QueryParamUtils;
import org.itboys.weixin.entity.WeixinConfig;
import org.itboys.weixin.service.WeixinConfigService;
import org.itboys.weixin.service.WeixinRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

@RestController
@RequestMapping(value = "/weixin/config")
public class WeixinConfigController extends BaseController {

	*/
/**
	 * 加载所有栏目页面上显示
	 * 
	 * @return
	 *//*

	@Autowired(required = false)
	private WeixinConfigService weixinConfigService;
	@Autowired(required = false)
	private WeixinRelService weixinRelService;
	@Autowired
	private ResourceHolder resourceHolder;

	@RequestMapping("/vm")
	public ModelAndView vm(HttpServletRequest request, Model model) {
		return new ModelAndView("/weixin/weixins/list");
	}

	@RequestMapping("/list")
	public void list(HttpServletResponse response, HttpServletRequest request) {
		final Map<String, Object> sqlMap = QueryParamUtils
				.builderQueryMap(request);
		LoginUser au = AdminSessionHolder.getAdminLoginUser();
		List<Long> weixinIds = Lists.newArrayList();
		if (au.getType() != 1) {
			Map<String, Object> map = Maps.newHashMap();
			map.put("userId", au.getUserid());
			List<Long> list = au.getRoleIds();
			if (list.size() == 1) {
				Long roleId = list.get(0);
				weixinIds = weixinRelService.list(roleId, "2");
			}
		}
		if (weixinIds.size() > 0) {
			sqlMap.put("weixinIds", weixinIds);
		}
		List<WeixinConfig> list = weixinConfigService.list(sqlMap);
		if (weixinIds.size() > 0) {
			for (WeixinConfig wc : list) {
				boolean hasParent = false;
				for (Long id : weixinIds) {
					if (wc.getParentId() == id) {
						hasParent = true;
						break;
					}
				}
				if (!hasParent) {
					wc.setParentId(0l);
				}
			}
		}
		JsonPageUtils.renderJsonPage(
				list != null && list.size() > 0 ? list.size() : 0L, list,
				response);
	}

	@RequestMapping("/listByProject")
	public void listByProject(HttpServletResponse response,
			HttpServletRequest request) {
		final Map<String, Object> sqlMap = QueryParamUtils
				.builderQueryMap(request);
		List<WeixinConfig> list = weixinConfigService.list(sqlMap);
		JsonPageUtils.renderJsonPage(
				list != null && list.size() > 0 ? list.size() : 0L, list,
				response);
	}
	
	*/
/**
	 * 返回所有的微信列表
	 * @param response
	 * @param request
	 *//*

	@RequestMapping("/allList")
	public void allList(HttpServletResponse response,
			HttpServletRequest request) {
		final Map<String, Object> sqlMap = QueryParamUtils
				.builderQueryMap(request);
		List<WeixinConfig> list = weixinConfigService.list(sqlMap);
		AjaxUtils.renderJson(response, list);
	}

	@RequestMapping("/getById")
	public ModelAndView getById(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String id = request.getParameter("id");
		String parentId = request.getParameter("parentId");
		WeixinConfig entity = new WeixinConfig();
		if (StringUtils.isNotBlank(id)) {
			entity = weixinConfigService.getById(Long.valueOf(id));
			model.addAttribute("entity", entity);
		}
		if (StringUtils.isNotBlank(parentId)) {
			WeixinConfig parententity = weixinConfigService.getById(Long
					.valueOf(parentId));
			String parentName = parententity.getName();
			model.addAttribute("parentName", parentName);
		}
		if (StringUtils.isNotBlank(parentId)) {
			model.addAttribute("parentId", parentId);
		}
		String flag = request.getParameter("flag");
		*/
/*model.addAttribute("staticRoot",resourceHolder.getStringValue("staticRoot"));
		model.addAttribute("adminRoot",resourceHolder.getStringValue("adminRoot"));
		model.addAttribute("imgRoot",resourceHolder.getStringValue("imgRoot"));*//*

		if (null != flag && flag.equals("1")) {
			return new ModelAndView("/weixin/weixins/projectinput");
		} else {
			return new ModelAndView("/weixin/weixins/input");
		}
	}

	@RequestMapping("/save")
	public void save(HttpServletResponse response,
			@ModelAttribute WeixinConfig weixinConfig,
			@RequestParam("logoImage") MultipartFile logoImage,
			@RequestParam("ewmImage") MultipartFile ewmImage,
			@RequestParam("ewmImage1") MultipartFile ewmImage1,
			@RequestParam("ewmImage2") MultipartFile ewmImage2,
			@RequestParam("ewmImage3") MultipartFile ewmImage3,
			@RequestParam("ewmImage4") MultipartFile ewmImage4,
			@RequestParam("keyStoreTemp") MultipartFile keyStoreTemp) {
		try {
			if (logoImage != null && !logoImage.isEmpty()) {
				String filePath = FileUtils.saveFile(logoImage.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						logoImage.getOriginalFilename(), logoImage.getContentType());
				weixinConfig.setLogo(filePath);
			}
			if (ewmImage != null && !ewmImage.isEmpty()) {
				String filePath1 = FileUtils.saveFile(ewmImage.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						ewmImage.getOriginalFilename(), ewmImage.getContentType());
				weixinConfig.setEwm(filePath1);
			}
			if (ewmImage1 != null && !ewmImage1.isEmpty()) {
				String filePath1 = FileUtils.saveFile(ewmImage1.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						ewmImage1.getOriginalFilename(), ewmImage1.getContentType());
				weixinConfig.setEwm1(filePath1);
			}
			if (ewmImage2 != null && !ewmImage2.isEmpty()) {
				String filePath1 = FileUtils.saveFile(ewmImage2.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						ewmImage2.getName(), ewmImage2.getContentType());
				weixinConfig.setEwm2(filePath1);
			}
			if (ewmImage3 != null && !ewmImage3.isEmpty()) {
				String filePath1 = FileUtils.saveFile(ewmImage3.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						ewmImage3.getName(), ewmImage3.getContentType());
				weixinConfig.setEwm3(filePath1);
			}
			if (ewmImage4 != null && !ewmImage4.isEmpty()) {
				String filePath1 = FileUtils.saveFile(ewmImage4.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						ewmImage4.getName(), ewmImage4.getContentType());
				weixinConfig.setEwm4(filePath1);
			}
			if (keyStoreTemp != null && !keyStoreTemp.isEmpty()) {
				String filePath1 = FileUtils.saveFile(keyStoreTemp.getInputStream(),
						resourceHolder.getStringValue("fileUploadPath"),
						keyStoreTemp.getName(), keyStoreTemp.getContentType());
				weixinConfig.setKeyStore(filePath1);
			}

			if (weixinConfig.getId() == 0L) {
				AdminSessionHolder.prepareAdminLoginData(weixinConfig);
				weixinConfigService.save(weixinConfig);
			} else {
				weixinConfigService.update(weixinConfig);
			}
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	@RequestMapping("/saveByProject")
	public void saveByProject(HttpServletResponse response,
			@ModelAttribute WeixinConfig weixinConfig,
			@RequestParam("logoImage") CommonsMultipartFile logoImage,
			@RequestParam("ewmImage") CommonsMultipartFile ewmImage,
			@RequestParam("ewmImage1") CommonsMultipartFile ewmImage1,
			@RequestParam("ewmImage2") CommonsMultipartFile ewmImage2,
			@RequestParam("ewmImage3") CommonsMultipartFile ewmImage3,
			@RequestParam("ewmImage4") CommonsMultipartFile ewmImage4,
			@RequestParam("keyStoreTemp") CommonsMultipartFile keyStoreTemp) {
		this.save(response, weixinConfig, logoImage, ewmImage, ewmImage1,
				ewmImage2, ewmImage3, ewmImage4,keyStoreTemp);
	}

	@RequestMapping("/delete")
	public void delete(HttpServletResponse response, HttpServletRequest request) {
		try {
			Long id = Long.valueOf(request.getParameter("id"));
			AjaxUtils.renderText(response,
					String.valueOf(weixinConfigService.delete(id)));
		} catch (Exception e) {
			logger.error("weixinconfig delete error", e);
			AjaxUtils.renderJson(response, 0);
		}
	}

	@RequestMapping("/checkname")
	public void checkname(HttpServletResponse response,
			HttpServletRequest request) {
		try {
			String id = request.getParameter("id");
			String name = request.getParameter("name");
			Map<String, Object> map = Maps.newHashMap();
			map.put("name", name);
			List<WeixinConfig> list = weixinConfigService.list(map);
			if (list != null
					&& (list.size() > 1 || (list.size() == 1
							&& StringUtils.isNotBlank(id) && list.get(0)
							.getId() != Long.valueOf(id)))) {
				AjaxUtils.renderJson(response, -1);// "微信公众账号名称已存在"
			}
			AjaxUtils.renderJson(response, 1);
		} catch (Exception e) {
			logger.error("weixinconfig checkname error", e);
			AjaxUtils.renderJson(response, 0);
		}
	}

}
*/
